import { fabric } from 'fabric';

import ObjectPool from './ObjectPool';

class Arrow extends fabric.Polygon {
  constructor(options = {}) {
    const points = [
      { x: -40, y: -10 },  // 左上
      { x: 10, y: -10 },   // 右上
      { x: 10, y: -25 },   // 右上箭头起点
      { x: 40, y: 0 },     // 箭头尖
      { x: 10, y: 25 },    // 右下箭头起点
      { x: 10, y: 10 },    // 右下
      { x: -40, y: 10 },   // 左下
    ];

    super(points, {
      fill: '#27ae60',
      strokeWidth: 1,
      stroke: '#000000',
      selectable: true,
      cornerSize: 10,
      transparentCorners: false,
      hasRotatingPoint: true,
      padding: 5,
      id: '',  // 添加id属性
      ...options,
    });

    // 确保控制点颜色与边框颜色一致
    this.set({
      cornerColor: this.stroke,
      borderColor: this.stroke,
    });
  }
}

// 创建一个全局的箭头对象池
const arrowPool = new ObjectPool(() => new Arrow());

// 导出Arrow类和arrowPool
export { Arrow, arrowPool };
export default Arrow;

